{% extends 'AdminBundle::layout.html.twig' %}

{% block title %}{% if data.id == 0 %}添加人员{% else %}编辑人员{% endif %}{% endblock %}

{% block css %}
    <link href="{{ asset('assets/css/combo.select.css') }}" rel="stylesheet">
{% endblock %}


{% block top %}
    {#{{ dump() }}#}
    {{ parent() }}
{% endblock %}

    {% block left_body_top %}
        {{ parent() }}
    {% endblock %}

    {% block left_body %}
        {{ parent() }}
    {% endblock %}

    {% block right_body %}
    <div class="page-header">
        <div class="page-right-top">
            <div class="right-top">
                <span class="right-title">人员管理</span>
            </div>
            <div class="top-nav top-nav-active">{% if data.id == 0 %}添加人员{% else %}编辑人员{% endif %}</div>
        </div>
        <div class="main-content">
            <form id="member-submit">
                <div class="mes-content" style="margin-top: 0;padding-top: 40px;">
                    <div class="add-mem-box">
                        <div class="mem-left fl">公司名称</div>
                        <div class="mem-right fl" style="padding: 0 !important;width:574px;">
                            <select name="company_name">
                                <option value="">请输入或选择公司名称</option>
                                {% for item in data.company %}
                                <option value="{{ item.name }}" {% if data.id > 0 and item.name == data.company_full_name %}selected{% endif %}>{{ item.name }}</option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="add-mem-box">
                        <div class="mem-left fl">姓名</div>
                        <input type="text" {% if data.id > 0 %} value="{{ data.name|default }}" {% endif %} class="mem-right fl" name="name" placeholder="请输入企业联络人姓名">
                        <div class="clearfix"></div>
                    </div>
                    <div class="add-mem-box">
                        <div class="mem-left fl">手机号码</div>
                        <input type="text" {% if data.id > 0 %} readonly value="{{ data.phone|default }}" {% endif %} class="mem-right fl" {% if data.id == 0 %}name="phone"{% endif %} placeholder="请输入企业联络人手机号码">
                        <div class="clearfix"></div>
                    </div>
                    <div class="add-mem-box">
                        <div class="mem-left fl">邮箱</div>
                        <input type="text" {% if data.id > 0 %} value="{{ data.email|default }}" {% endif %} class="mem-right fl" name="email" placeholder="请输入企业联络人邮箱">
                        <div class="clearfix"></div>
                    </div>
                    <div class="add-mem-box">
                        <div class="mem-left fl">职业</div>
                        <input type="text" {% if data.id > 0 %} value="{{ data.position_name|default }}" {% endif %} class="mem-right fl" name="position" placeholder="请输入企业联络人职位">
                        <div class="clearfix"></div>
                    </div>
                    <div class="add-mem-box" style="margin-top: 40px;">
                        <div class="mem-left fl"></div>
                        <div class="acc-opera-btn fl mem-btn" style="margin-left: 42px;">保存</div>
                        <div class="acc-opera-btn fl mem-cancel">取消</div>
                    </div>

                    <div class="clearfix"></div>
                </div>
            </form>
        </div>
    </div>
    {% endblock %}

{% block box %}{% endblock %}

{% block javascript %}
<script src="{{ asset('assets/js/jquery.combo.select.js') }}"></script>
<script type="text/javascript">
    $(function () {
        SidebarHighlighting('3');

        $('select').comboSelect();

        $(".mem-btn").on('click', function(){
            var param = $('#member-submit').serializeObject();
            console.log(param);

            if(param.company_name == "" && $.trim($(".combo-input.text-input").val()) == ""){
                popStatus(2, '请输入或选择公司名称',1,'',true);
                return;
            }

            if(param.company_name == "" && $.trim($(".combo-input.text-input").val()) != ""){
                popStatus(2, '公司不存在',1,'',true);
                return;
            }

            if(param.name == ""){
                popStatus(2, '请输入姓名',1,'',true);
                return;
            }

            {% if data.id == 0 %}
            if(param.phone == ""){
                popStatus(2, '请输入手机号',1,'',true);
                return;
            }
            {% endif %}

            if(param.email == ""){
                popStatus(2, '请输入邮箱',1,'',true);
                return;
            }
            if(param.position == ""){
                popStatus(2, '请输入职位',1,'',true);
                return;
            }
            param.id = "{{ data.id|default('0') }}";

            $.post("{{ path('api_admin_add_personnel_list') }}",param,function (data) {
                console.log(data);
                if(data.errorCode == 0){
                    popStatus(1, data.message,1,"{{ path('personal_list_index') }}",true);
                } else {
                    popStatus(2, data.message,1,'',true);
                }
            })


        })

        $(".mem-cancel").click(function(){
            location.href = "{{ path('personal_list_index') }}";
        })
    })
</script>
{% endblock %}